import Mock, { Random } from 'mockjs';


const { data } = Mock.mock({
    data:
    {
        telcode: Random.string('number', 4),
    }

})

const { data1 } = Mock.mock({
    data1: {
        tel: '10086',
        isState: true,
        token: '123456',
    }
})

const { data2 } = Mock.mock({
    data2: {
        name: '10086',
        password: '123456',
        token: '123456',
        isState: true,
    }
})

Mock.mock('/api/code', 'post', () => {

    return {
        code: 200,
        message: '获取数据成功',
        data: {
            data
        }
    }
})



Mock.mock('/api/codelogin', 'post', (config) => {

    const { tel, code } = JSON.parse(config.body)
    if (tel === data1.tel && code === data.telcode) {

        return {
            code: 200,
            message: '登录成功',
            data: data1
        }

    } else {

        return {
            code: 400,
            message: '登录失败',

        }
    }


})


Mock.mock('/api/login', 'post', (config) => {


    const { tel, password } = JSON.parse(config.body)
    if (tel === data2.name && password === data2.password) {

        return {
            code: 200,
            message: '登录成功',
            data: data1
        }

    } else {

        return {
            code: 400,
            message: '登录失败',
        }
    }
})